/* 用户个人资料页面布局组件，包含认证检查和页面结构 */
import { Header } from "@components/header";
import { authProviderServer } from "@providers/auth-provider/auth-provider.server";
import { ThemedLayoutV2 } from "@refinedev/antd";
import { redirect } from "next/navigation";
import React from "react";


/**
 * 用户个人资料页面布局组件
 * 处理认证状态检查并重定向未登录用户
 * @param children - 布局内的子组件内容
 */
export default async function Layout({ children }: React.PropsWithChildren) {
  const data = await getData();

  if (!data.authenticated) {
    return redirect(data?.redirectTo || "/login");
  }

  return <ThemedLayoutV2 Header={Header}>{children}</ThemedLayoutV2>;
}

/**
 * 获取用户认证状态数据
 * 通过authProviderServer检查用户登录状态
 * @returns 包含认证状态和重定向URL的对象
 */
async function getData() {
  const { authenticated, redirectTo } = await authProviderServer.check();

  return {
    authenticated,
    redirectTo,
  };
}